<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%@ page import="com.sap.mw.jco.IFunctionTemplate" %>
<%@ page import="com.sap.mw.jco.JCO" %>
<%@ page import="com.weaver.general.BaseBean" %>
<%@ page import="com.weaver.integration.datesource.SAPInterationOutUtil" %>
<%@ page import="com.weaver.integration.log.LogInfo" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.HashMap" %>
<jsp:useBean id="rs" class="weaver.conn.RecordSet" scope="page"/>
<jsp:useBean id="bb" class="weaver.general.BaseBean"/>
<%
    String gys = Util.null2String(request.getParameter("gys"));//供应商
    String sapcode = Util.null2String(request.getParameter("sapcode").toUpperCase());//sap code
    bb.writeLog("gys=" + gys + ",sapcode=" + sapcode);
    Map<String, String> map = new HashMap<>();
    map.put("I_LIFNR", gys);
    map.put("I_MATNR", sapcode);
    Map<String, String> returnMap = execute(map);
    String netpr = Util.null2String(returnMap.get("netpr"));    // 采购凭证中的净价(以凭证货币计)
    String mfrpn = Util.null2String(returnMap.get("mfrpn"));    //制造商零件编号
    String stawn = Util.null2String(returnMap.get("stawn"));    //外贸的商品代码和进口代码
    String maktx = Util.null2String(returnMap.get("maktx"));    //物料描述（短文本）
    String waers = Util.null2String(returnMap.get("waers"));    //货币码
    String str = "{\"netpr\":\"" + netpr + "\",\"mfrpn\":\"" + mfrpn + "\",\"stawn\":\"" + stawn + "\",\"maktx\":\"" + maktx + "\",\"waers\":\"" + waers + "\"}";

    bb.writeLog(str);
    out.print(str);
%>
<%!
    public static Map execute(Map<String, String> map) {
        SAPInterationOutUtil outUtil = new SAPInterationOutUtil();
        BaseBean baseBean = new BaseBean();
        baseBean.writeLog("in---ZBPM_MATERIAL_LIST");
        JCO.Client myConnection = (JCO.Client) outUtil.getConnection("2", new LogInfo());
        myConnection.connect();
        JCO.Repository myRepository = new JCO.Repository("Repository", myConnection); // 只一个名字
        IFunctionTemplate ft = myRepository.getFunctionTemplate("ZBPM_MATERIAL_LIST");//设置BAPI函数
        JCO.Function bapi = ft.getFunction();
        JCO.ParameterList input = bapi.getImportParameterList();//输入参数和结构处理
        JCO.ParameterList inputtable = bapi.getTableParameterList();//输入表的处理
        //输入参数
        input.setValue(map.get("I_LIFNR"), "I_LIFNR");//供应商编号
        input.setValue(map.get("I_MATNR"), "I_MATNR");//SAP Code
        //执行函数
        myConnection.execute(bapi);
        JCO.ParameterList out = bapi.getExportParameterList();//输出参数和结构处理
        JCO.ParameterList Table00 = bapi.getTableParameterList();//输出表的处理

        //返回处理结果以及日志
        JCO.Table tabs = Table00.getTable("IT_MATNR");
        baseBean.writeLog("SPA_COUNTS:" + tabs.getNumRows());
        Map<String, String> resultMap = new HashMap<>();
        String netpr = Util.null2String(tabs.getValue("NETPR"));    // 采购凭证中的净价(以凭证货币计)
        String mfrpn = Util.null2String(tabs.getValue("MFRPN"));    //制造商零件编号
        String stawn = Util.null2String(tabs.getValue("STAWN"));    //外贸的商品代码和进口代码
        String maktx = Util.null2String(tabs.getValue("MAKTX"));    //物料描述（短文本）
        String waers = Util.null2String(tabs.getValue("WAERS"));    //货币码
        resultMap.put("netpr", netpr);
        resultMap.put("mfrpn", mfrpn);
        resultMap.put("stawn", stawn);
        resultMap.put("maktx", maktx);
        resultMap.put("waers", waers);
        //返回处理结果以及日志
        JCO.releaseClient(myConnection);
        return resultMap;
    }

%>
